﻿using System;

namespace GoogleReaderToDelicious.Core.Model
{
    //13-sep-2010 Priyan R
    public class DatabaseContext : GoogleReaderDataEntities
    {
        public DatabaseContext()
            : base()
        {
            //  this.ContextOptions.LazyLoadingEnabled = false;
            this.Configuration.LazyLoadingEnabled = false;
        }



        public void Add<T>(T entity) where T : class
        {
            this.Set(typeof(T)).Add(entity);
            //  this.CreateObjectSet<T>().AddObject(entity);
        }
        public void Delete<T>(T entity) where T : class
        {
            this.Set(typeof(T)).Remove(entity);
            // this.CreateObjectSet<T>().DeleteObject(entity);
        }
        public static DatabaseContext Create()
        {
            return new DatabaseContext();

        }


        public int ExecuteSqlCommand(string sql, params object[] parameters)
        {

            return Database.ExecuteSqlCommand(sql, parameters);
        }

        public void LoadProperty<TEntity>(TEntity entity,
            System.Linq.Expressions.Expression<Func<TEntity, object>> selector)
            where TEntity : class
        {

            this.Entry(entity)
                .Reference(selector).Load();

        }
        public void Reload<TEntity>(TEntity entity) where TEntity : class
        {
            this.Entry(entity).Reload();
        }
    }
}
